using System;

// 定义一个接口，包含计算面积和判断合法性的方法
public interface IShape
{
    double Area { get; }
    bool IsValid { get; }
}

// 定义一个抽象类，实现 IShape 接口
public abstract class Shape : IShape
{
    public abstract double Area { get; }
    public abstract bool IsValid { get; }
}

// 长方形类
public class Rectangle : Shape
{
    public double Length { get; set; }
    public double Width { get; set; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public override double Area
    {
        get
        {
            return Length * Width;
        }
    }

    public override bool IsValid
    {
        get
        {
            return Length > 0 && Width > 0;
        }
    }
}

// 正方形类，继承自长方形类
public class Square : Rectangle
{
    public Square(double side) : base(side, side)
    {
    }
}

// 三角形类
public class Triangle : Shape
{
    public double SideA { get; set; }
    public double SideB { get; set; }
    public double SideC { get; set; }

    public Triangle(double sideA, double sideB, double sideC)
    {
        SideA = sideA;
        SideB = sideB;
        SideC = sideC;
    }

    public override double Area
    {
        get
        {
            if (!IsValid)
            {
                return 0;
            }
            double s = (SideA + SideB + SideC) / 2;
            return Math.Sqrt(s * (s - SideA) * (s - SideB) * (s - SideC));
        }
    }

    public override bool IsValid
    {
        get
        {
            return SideA > 0 && SideB > 0 && SideC > 0 &&
                   SideA + SideB > SideC &&
                   SideA + SideC > SideB &&
                   SideB + SideC > SideA;
        }
    }
}

class Program
{
    static void Main()
    {
        // 创建长方形对象
        Rectangle rectangle = new Rectangle(5, 3);
        Console.WriteLine($"Rectangle Area: {rectangle.Area}, Is Valid: {rectangle.IsValid}");

        // 创建正方形对象
        Square square = new Square(4);
        Console.WriteLine($"Square Area: {square.Area}, Is Valid: {square.IsValid}");

        // 创建三角形对象
        Triangle triangle = new Triangle(3, 4, 5);
        Console.WriteLine($"Triangle Area: {triangle.Area}, Is Valid: {triangle.IsValid}");
    }
}